package com.wm.blog_admin.dao;


import com.wm.blog_admin.mapper.TBlogMapper;
import com.wm.blog_admin.query.TBlogQuery;
import com.wm.blog_common.base.BaseDAO;
import com.wm.blog_common.domain.TBlogDO;
import com.wm.blog_common.entity.TBlog;
import com.wm.blog_common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * <p>
 * 博客表 服务DAO层
 * </p>
 *
 * @author wm_yu
 * @since 2020-03-24
 */
@Repository
public class TBlogDAO extends BaseDAO<TBlogMapper, TBlog> {

    @Autowired
    private TBlogMapper tBlogMapper;

    public List<TBlogDO> blogSortPie(TBlogQuery query) {
        query = Optional.ofNullable(query).orElse(new TBlogQuery());
        return tBlogMapper.blogSortPie(query);
    }

    /**
     * 用户点击数量
     * @param query
     * @return
     */
    public int clickCount(TBlogQuery query) {
        query = Optional.ofNullable(query).orElse(new TBlogQuery());
        return tBlogMapper.clickCount(query);
    }


    public Result<List<TBlogDO>> weekActive(TBlogQuery query) {
        query = Optional.ofNullable(query).orElse(new TBlogQuery());
        return Result.success(Optional.ofNullable(tBlogMapper.weekActive(query)).orElse(Collections.emptyList()));
    }

}

